package com.hejr.controller;

import com.hejr.test01.service.IUserOneService;
import com.hejr.test02.service.IUserTwoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: hejr
 * @desc: 多数据源分布式事务控制类
 * @date: 2019/4/9 11:20
 */
@RestController
public class UserController {

    @Autowired
    @Qualifier("userOneService")
    private IUserOneService userOneService;

    @Autowired
    private IUserTwoService userTwoService;

    @RequestMapping("/addUserOne")
    public Integer addUserOne(String name, Integer age) {
        return userOneService.addUser(name, age);
    }

    @RequestMapping("/addUserTwo")
    public Integer addUserTwo(String name, Integer age) {
        return userTwoService.addUser(name, age);
    }

    /**
     * 同时往两个库新增用户，目的为了测试事务回滚
     * @param name
     * @param age
     * @return
     */
    @RequestMapping("/addAllUser")
    public int addAllUser(String name, Integer age) {
        return userTwoService.addAllUser(name, age);
    }
}
